package Util;

import java.lang.reflect.Type;
import java.math.BigDecimal;

public class BigDecimalUtil {
    private BigDecimalUtil(){}

    public static BigDecimal add(double v1,double v2){
        BigDecimal b1=new BigDecimal(Double.toString(v1));
        BigDecimal b2=new BigDecimal(Double.toString(v2));
        return b1.add(b2);
    }
    private static  BigDecimal sub(double v1,double v2){
        BigDecimal b1=new BigDecimal(Double.toString(v1));
        BigDecimal b2=new BigDecimal(Double.toString(v2));
        return  b1.subtract(b2);
    }
    private static BigDecimal mul(double v1,double v2){
        BigDecimal b1=new BigDecimal(Double.toString(v1));
        BigDecimal b2=new BigDecimal(Double.toString(v2));
        return b1.multiply(b2);
    }
    private static BigDecimal div(double v1,double v2){
        BigDecimal b1=new BigDecimal(Double.toString(v1));
        BigDecimal b2=new BigDecimal(Double.toString(v2));
        return b1.divide(b2,2,BigDecimal.ROUND_HALF_UP);//四舍五入保留两位小数
    }

    public static void main(String[] args) {
        System.out.println(new BigDecimal(1.2));
        BigDecimal bigDecimal = new BigDecimal("1.2");
        System.out.println(bigDecimal.getClass());
        System.out.println(new BigDecimal("1.2"));
        System.out.println(2.0-1.1);
        System.out.println(BigDecimalUtil.sub(2.0,1.1));
    }
}
